/*************************************************************************
	> File Name: udp_client.c
	> Author: Maureen 
	> Mail: 1437867946@qq.com 
	> Created Time: Mon 11 Jan 2021 09:46:41 PM CST
 ************************************************************************/

#include "head.h"

extern int port;

int socket_udp() {
    int sockfd;
    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
        return -1;
    }
    return sockfd;
}

int udp_connect(struct sockaddr_in *client) {
    int sockfd;
    if ((sockfd = socket_create_udp(port)) < 0) { //创建socket
        return -1;
    }
    
    client->sin_port = htons(8888);

    if (connect(sockfd, (struct sockaddr *)client, sizeof(struct sockaddr)) < 0) { //连接到对应的client
        return -1;
    }

    return sockfd;
}
